<?php 
if (!defined("LEVEL") || LEVEL < 30 || !defined("OK")) { header('location: ?'); exit; }

//Nustatom pagal ka rusiuosim
if (isset($url['o']) && !empty($url['o'])) { 
	switch ($url['o']) {
		case "Slapyvardis": {
			$order = "nick";
			break;
		}
		case "Nr:": {
			$order = "id";
			break;
		}
		case "e-pa%C5%A1tas": {
			$order = "email";
			break;
		}
		case "IP": {
			$order = "ip";
			break;
		}
		case "U%C5%BEsiregistravo": {
			$order = "reg_data";
			break;
		}
		case "Prisijung%C4%97": {
			$order = "login_data";
			break;
		}
		default: {
			$order = "id";
			break;
		}
	}
}
//nustatom mazejancia ar didejancia tvarka
if (isset($url['w']) && !empty($url['w'])) { 
	switch ($url['w']) {
		case "d": {
			$order .= " DESC";
			break;
		}
		case "a": {
			$order .= " ASC";
			break;
		}
		default: {
			$order .= " ASC";
			break;
		}
	}
}
else { $order = "id ASC"; }

if (isset($url['d']) && $url['d'] != "" && $url['d'] != 0) {
	mysql_query("DELETE FROM `".LENTELES_PRIESAGA."users` WHERE id=".escape((int)$url['d'])." AND levelis<30") or die(mysql_error());
	header("Location: ".url('d,0'));
}
//paruosiam klase lenteliu paisymui
include_once("priedai/class.php");

		//adminu saras
		$sql = mysql_query1("SELECT id, INET_NTOA(ip) AS ip, reg_data, gim_data, login_data, nick, vardas, pavarde, email FROM `".LENTELES_PRIESAGA."users` WHERE levelis=30"); $i=0;
		if (mysql_num_rows($sql) > 0) {
			while($row = mysql_fetch_assoc($sql)) {
				$i++;
				$info[] = array(
				//"Nr:"=>$row['id'],
				"Slapyvardis"=> "<a href=\"?id,47;m,".$row['id']."\" title=\"".$row['reg_data']."\">".$row['nick']."</a> <a href=\"?id,45;n,1;u,".$row['nick']."\"><img src=\"images/pm/mail.png\" alt=\"pm\" border=\"0\"></img></a>",
				//"IP"=>$row['ip'],
				//"Užsiregistravo" => kada($row['reg_data']),
				//"Prisijungė"=>kada($row['login_data']),
				"e-paštas"=>preg_replace("#([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "<a href=\"javascript:mailto:mail('\\1','\\2');\">\\1_(at)_\\2</a>", $row['email']),
				//"Vardas"=>$row['vardas']." ".$row['pavarde'],
				//"Amžius"=>amzius($row['gim_data'])."m.",
				"Valdymas"=>"<a href='?id,46;a,6;r,102'>[r]</a>"
				);
			}
			//nupiesiam adminu lentele
			$bla = new Table();
			lentele("Administratoriu",$bla->render($info),false,array('Viso',$i));
			unset($info,$i);
		} else { klaida("Administratoriu","Administratorių nėra. Šeip čia kažkoks nesusipratimas turbūt. Greičiausiai duombazės problemos"); }
		
		//moderatoriu sarasas
		$sql = mysql_query1("SELECT id, INET_NTOA(ip) AS ip, reg_data, gim_data, login_data, nick, vardas, pavarde, email FROM `".LENTELES_PRIESAGA."users` WHERE levelis>19 AND levelis<30"); $i=0;
		if (mysql_num_rows($sql) > 0) {
			while($row = mysql_fetch_assoc($sql)) {
				$i++;
				$info1[] = array(
				//"Nr:"=>$row['id'],
				"Slapyvardis"=> "<a href=\"?id,47;m,".$row['id']."\" title=\"".$row['reg_data']."\">".$row['nick']."</a> <a href=\"?id,45;n,1;u,".$row['nick']."\"><img src=\"images/pm/mail.png\" alt=\"pm\" border=\"0\"></img></a>",
				"IP"=>$row['ip'],
				//"Užsiregistravo" => kada($row['reg_data']),
				//"Prisijungė"=>kada($row['login_data']),
				"e-paštas"=>preg_replace("#([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "<a href=\"javascript:mailto:mail('\\1','\\2');\">\\1_(at)_\\2</a>", $row['email']),
				//"Vardas"=>$row['vardas']." ".$row['pavarde'],
				//"Amžius"=>amzius($row['gim_data'])."m.",
				"Valdymas"=>"<button onclick=\"if (confirm('Ar tikrai nori ištrinti?')) window.location='".url("d,".$row['id'])."'; else return false;\">X</button> <a href='?id,46;a,6;r,102'>[r]</a> <a href='?id,46;a,6;b,".$row['ip']."'>[b]</a>"
				);
			}
			//nupiesiam moderatoriu lentele
			$bla = new Table();
			lentele("Moderatorių",$bla->render($info1),false,array('Viso',$i));
			unset($info1,$i);
		} else { klaida("Moderatorių","Svetainė neturi moderatorių"); }
		echo "<hr>";
		
		//vartotoju sarasas
		$sql = mysql_query1("SELECT id, INET_NTOA(ip) AS ip, reg_data, login_data, gim_data, nick, vardas, pavarde, email FROM `".LENTELES_PRIESAGA."users` WHERE levelis<20 ORDER BY $order"); $i=0;
		if (mysql_num_rows($sql) > 0) {
			while($row = mysql_fetch_assoc($sql)) {
				$i++;
				$info2[] = array(
				//"Nr:"=>$row['id'],
				"Slapyvardis"=> "<a href=\"?id,47;m,".$row['id']."\" title=\"".$row['reg_data']."\">".$row['nick']."</a> <a href=\"?id,45;n,1;u,".$row['nick']."\"><img src=\"images/pm/mail.png\" alt=\"pm\" border=\"0\"></img></a>",
				"IP"=>$row['ip'],
				//"Užsiregistravo" => kada($row['reg_data']),
				//"Prisijungė"=>kada($row['login_data']),
				"e-paštas"=>preg_replace("#([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "<a href=\"javascript:mailto:mail('\\1','\\2');\">\\1_(at)_\\2</a>", $row['email']),
				//"Vardas"=>$row['vardas']." ".$row['pavarde'],
				//"Amžius"=>amzius($row['gim_data'])."m.",
				"Valdymas"=>"<button onclick=\"if (confirm('Ar tikrai nori ištrinti?')) window.location='".url("d,".$row['id'])."'; else return false;\">X</button> <a href='?id,46;a,6;r,102'>[r]</a> <a href='?id,46;a,6;b,".$row['ip']."'>[b]</a>"
				);
			}
			//nupiesiam vartotoju lentele
			$bla = new Table();
			lentele("Vartotoju - ".$i,$bla->render($info2),false,array('Viso',$i));
			unset($info2,$i);
		} else { klaida("Vartotojų","Svetainėje nėra neivieno registruoto vartotojo"); }
		?>
</div>